<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var pairSums = function (nums, target) {
      nums.sort((a, b) => a - b)
      let l = 0, r = nums.length - 1, ans = []
      while (l < r) {
        if (nums[l] + nums[r] == target) {
          ans.push([nums[l], nums[r]])
          l++
          r--
        } else if ((nums[l] + nums[r]) > target) {
          r--
        } else {
          l++
        }
      }

      return ans
    };
    console.log(pairSums(nums = [5, 6, 5, 6], target = 11))
  </script>
</body>

</html>